package model;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Transient;

import rmi.client.Client;


@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.INTEGER, name="userTypeId")
abstract public class User implements UserInterface
{
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int userId;
	
	@Column(nullable=false)
	protected String username;
	
	@Column(nullable=false)
	protected String password;
	
	@Transient
	protected Client client;
	
	public User()
	{
		
	}
	
	public User(String username)
	{
		this.username = username;
	}
	
	public void setClient(Client client)
	{
		this.client = client;
	}
	
	public Client getClient()
	{
		return client;
	}
	
	public int getId()
	{
		return userId;
	}
	
	public int getUserId()
	{
		return userId;
	}
	
	public String getUsername()
	{
		return username.substring(0, 1).toUpperCase() + username.substring(1);
	}

	public boolean equalsPassword(char[] password)
	{
		return String.valueOf(password).equals(this.password);
	}

	public boolean equalsPassword(String password)
	{
		return password.equals(this.password);
	}
	
	public void setPassword(char[] password)
	{
		this.password = String.valueOf(password);
	}
	
	public void setPassword(String password)
	{
		this.password = password;
	}
	
	public String getPassword()
	{
		return password;
	}
	
	public boolean check()
	{
		return true;
	}
}
